<?php

namespace maotool\core\text\password\rule;

use maotool\core\text\password\PasswdStrengthItem;
use maotool\core\text\password\PasswdStrengthRule;
use maotool\core\text\password\result\PasswdStrengthError;
use maotool\core\text\password\result\PasswdStrengthSuccess;

class MinLengthRule implements PasswdStrengthRule
{

    protected $min;

    protected $message;

    public function __construct($min = 6, $message = "密码长度太短")
    {
        $this->min = $min;
        $this->message = $message;
    }

    function handle($password)
    {
        if (strlen($password) < $this->min) {
            $passwdStrengthError = new PasswdStrengthError();
            $passwdStrengthError->setMessage($this->message);
            $passwdStrengthError->setName("minLength");
            return $passwdStrengthError;
        }
        $passwdStrengthSuccess = new PasswdStrengthSuccess();
        $passwdStrengthSuccess->setName("minLength");
        return $passwdStrengthSuccess;
    }

}